package design_master.yin97.com.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.button);
        Button button1 = (Button) findViewById(R.id.button2);
         imageView = (ImageView) findViewById(R.id.imageView);
        button.setOnClickListener(this);
        button1.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.button:
                CropImageUtils.getInstance().takePhoto(this);
                break;

            case R.id.button2:
                CropImageUtils.getInstance().openAlbum(this);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        CropImageUtils.getInstance().onActivityResult(MainActivity.this, requestCode, resultCode, data, new CropImageUtils.OnResultListener()
        {
            @Override
            public void takePhotoFinish(String path)
            {
                // ToastUtils.showToast("照片存放在：" + path);                //拍照回调，去裁剪
                CropImageUtils.getInstance().cropPicture(MainActivity.this, path);
            }
            @Override
            public void selectPictureFinish(String path) {
                //ToastUtils.showToast("打开图片：" + path);    //相册回调，去裁剪
                CropImageUtils.getInstance().cropPicture(MainActivity.this, path);
            }
            @Override
            public void cropPictureFinish(String path) {
                Glide.with(MainActivity.this)
                        .load(path)
                        .into(imageView);;
                // ToastUtils.showToast("裁剪保存在：" + path);   //裁剪回调


            }
        });
    }
}
